﻿public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }
    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}
//泛型链表类
public class GenericList<T>
{
    private Node<T> head;
    private Node<T> tail;
    public GenericList()
    {
        tail = head = null;
    }
    public Node<T> Head
    {
        get => head;
    }
    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if (head == null)
        {
            head = tail = n;
        }
        else
        {

            tail.Next = n;
            tail = n;

        }
        tail.Next = null;
    }
    public IEnumerator<T> GetEnumerator()
    {
        for (Node<T> current = head; current != null; current = current.Next)
            yield return current.Data;//yield return an element a time
    }
}
class Pro
{
    static void Main(string[] args)
    {
        GenericList<int> intlist = new GenericList<int>();
        for (int x = 0; x < 10; x++)
            intlist.Add(x);
    }
    foreach(int x in intlist)
     {
        Console.WriteLine(x);
     }
GenericList<string> strlist = new GenericList<string>();
for (int x = 0; x < 10; x++)
{
    strlist.Add("str" +x);
}
foreach(string str in strlist)
{
    Console.WriteLine(str);
}
}